import provinces from './china-division/provinces';
import cities from './china-division/cities';
import areas from './china-division/areas';

const AreaOptions = () => {
    const result = [];
    for ( let city of cities ) {
        const cityCode = city.code;
        let children = [];
        for ( let area of areas ) {
            if (area.cityCode === cityCode) {
                children.push({
                    label: area.name,
                    value: area.code
                });
            }
        }
        city.children = children;
    }

    for ( let province of provinces ) {
        const provinceCode = province.code;
        let children = [];
        for ( let city of cities ) {
            if (city.provinceCode === provinceCode) {
                children.push({
                    label: city.name,
                    value: city.code,
                    children: city.children
                });
            }
        }
        result.push({
            label: province.name,
            value: province.code,
            children: children
        });
    }
    return result;
};

export default AreaOptions;